import 'package:flutter/material.dart';
import 'package:whale/helper/component/carousel_text.dart';
import 'package:whale/helper/utils/util.dart';

import '../../../../helper/component/carousel_text_status.dart';
import '../index.dart';

/// hello
class TotalDataView extends GetView<WatchController> {
  const TotalDataView({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    var state = controller.state;
    return Container(
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(2.r),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            height: 110.r,
            width: 345.r,
            padding: EdgeInsets.only(top: 18.r,left: 20.r),
            decoration: BoxDecoration(
              borderRadius: BorderRadius.vertical(top: Radius.circular(2.r)),
              image: DecorationImage(image: AssetImage('bg_watch1.png'.imgPathWatch),fit: BoxFit.fill)
            ),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  '公平竞争大数据监测',
                  style: TextStyle(
                    color: Colors.white,
                    fontSize: 14.sp,
                  ),
                ),
                SizedBox(height: 10.r,),
                Text(
                  '1,233,018',
                  style: TextStyle(
                    color: Colors.white,
                    fontWeight: FontWeight.bold,
                    fontSize: 36.sp,
                  ),
                ),
                // Container(
                //   margin: EdgeInsets.fromLTRB(0, 15.r, 0, 10.r),
                //   child: NumbersPieceView(data: 1233263),
                // ),
              ],
            ),
          ),

          isZeroList(state.carouselData)
              ? const SizedBox()
              : CarouselStatusText(
            list: state.carouselData!,
            lineCount: 1,
            height: 42.r,
            color: ColorsUtil.title,
          )
        ],
      ),
    );
  }
}

class NumbersPieceView extends StatelessWidget {
  const NumbersPieceView({Key? key, required this.data}) : super(key: key);
  final int data;
  List<Widget> _buildItems() {
    List<Widget> items = [];
    var str = data.toString();
    for (var i = 0; i < str.length; i++) {
      var j = str.length - i;
      var c = str.substring(i, i + 1);

      if (j % 3 == 0 && j != 0) {
        items.add(
          Container(
            width: 10.r,
            alignment: Alignment.bottomCenter,
            child: Text(
              ',',
              style: TextStyle(
                color: ColorsUtil.title,
                fontSize: 14.sp,
              ),
            ),
          ),
        );
      } else {
        items.add(SizedBox(
          width: 5.r,
        ));
      }
      items.add(_buildPieceView(c));
    }
    return items;
  }

  @override
  Widget build(BuildContext context) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: _buildItems(),
    );
  }

  Widget _buildPieceView(String s) {
    return Container(
      decoration: BoxDecoration(
        color: ColorsUtil.theme,
        borderRadius: BorderRadius.circular(3),
      ),
      height: 30.r,
      width: 18.r,
      alignment: Alignment.center,
      child: Text(
        s,
        style: TextStyle(
          color: Colors.white,
          fontSize: 16.sp,
          fontWeight: FontWeight.bold,
        ),
      ),
    );
  }
}
